package com.zha.boss.events.listeners;

import com.zha.boss.client.mail.MailClient;
import com.zha.boss.client.mail.MailProperties;
import com.zha.boss.events.domain.NoticeMailEvent;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author: zha
 * @CreateTime: 2024年09月19日 14:30
 */
@Component
public class NoticeMailListeners implements ApplicationListener<NoticeMailEvent> {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Resource
    private MailClient mailClient;
    @Async
    @Override
    public void onApplicationEvent(NoticeMailEvent event) {
        logger.info("[NoticeMailEvent]处理程序开始执行");
        MailProperties mailProperties = event.getMailProperties();
        logger.info("[NoticeMailEvent]接收的邮件信息:{}", mailProperties.toString());
        boolean send = mailClient.sendSimpleMail(mailProperties);
        logger.info("[NoticeMailEvent]邮件发送结果:{}", send);
        logger.info("[NoticeMailEvent]处理程序执行完成");
    }
}
